#encoding:utf-8
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".

Replace this with more appropriate tests for your application.
"""

from django.test import TestCase
from django.test.client import Client
from szdb.adjtime import getDatetime, getNow
from szdb.models import User, Activity, News, NewsType

class MobileTestCase(TestCase):
    c = Client()
    def setUp(self):
        self.user = User()
        # 基础用户建立
        self.baseuser = User(username='zdz',
                             password='12345',
                             email='zdz@126.com',
                             type=1,
                             safequestion='我的手机号码',
                             safeanswer='13805728737',
                             sex=0,
                             )
        self.baseuser.save()
        # 基础活动建立
        self.acti = Activity(title='腐败一日游',
                             content='逛西湖一天',
                             releasetime=getNow(),
                             date=getNow(),
                             owner=self.baseuser,
                             place='杭州西湖',
                             )
        self.acti.save()
    def tearDown(self): # 完成单元测试收尾，清除环境
        pass


    def testLogin(self):
        """
        test mobile login interface 
        """
        response = self.c.post('/mobile/login',{'username':'zdz','password':'12345'})
        print response.content
        self.assertEqual(response.status_code, 200)
#    
#    def testRegister(self):
#        """
#        test mobile register interface
#        """
#        data = {'username':'zdz',
#            'password':12345,
#            'email':'ztj@126.com',
#            'safequestion':'我的电话号码',
#            'safeanswer':'13805728737',
#            'sex':1,
#        }
#        response = self.c.post('/mobile/register', data)
#        print 'register info ' + response.content
#        self.assertEqual(response.status_code, 200)
#        
#    
#    def testRetrieve_news(self):
#        """
#        test mobile retrieve 
#        """
#        response = self.c.post('/mobile/getNews',{'typeid':'1','lasttime':getDatetime('2012-04-24 23:28:15')})
#        #print response.content
#        self.assertEqual(response.status_code, 200)
##    
#    def testRetrieve_activity(self):
#        response = self.c.post('/mobile/getActivity',{'lasttime':getDatetime('2012-04-24 23:28:15')})
#        print response.content
#        self.assertEqual(response.status_code, 200)
#    
#    def testJoin_activity(self):
#        data = {'username':'zdz',
#                'activityid':1,
#                }
#        response = self.c.post('/mobile/joinActivity',data)
#        print response.content
#        self.assertEqual( response.status_code , 200)
#        
#    def testAdd_activity(self):
#        data = {'title':'腐败一日游2',
#                'content':'逛西湖一天2',
#                'releasetime':getNow(),
#                'date':getNow(),
#                'owner':'ztj',
#                'place':'杭州西湖2',
#                'uid' : 1
#        }
#        response = self.c.post('/mobile/startActivity', data)
#        print response.content
#        self.assertEqual(response.status_code, 200)
#        
#    def testReset_key(self):
#        data = {'username':'zdz',
#                'password':'12345',
#                'newpsw':'54321',
#                'newpsw2':'54321'
#        }
#        response = self.c.post('/mobile/resetKey',data)
#        self.assertEqual(response.status_code, 200)

#    
#    def testGet_key(self):
#        pass
#    def testCheck_username_false(self):
#        data={'username':'zdz'}
#        response = self.c.post('/mobile/checkusername', data)
#        print "check user name result " + response.content
#        
#    def testCheck_email_false(self):
#        data={'email':'zdz@126.com'}
#        response = self.c.post('/mobile/checkemail', data)
#        print "check email result " + response.content
#        
#    def testCheck_username_true(self):
#        data={'username':'zdz1'}
#        response = self.c.post('/mobile/checkusername', data)
#        print "check user name result " + response.content
#        
#    def testCheck_email_true(self):
#        data={'email':'zdz1@126.com'}
#        response = self.c.post('/mobile/checkemail', data)
#        print "check email result " + response.content
    
    
        
        
    
